{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% import "user/partial/search_user_form.html" as search_user_form_macro %}
{% import "user/partial/user_table.html" as user_table_macro %}

{% block title %}万屏时代OPC--用户列表{% endblock %}

{% block panel_heading %}
  万屏时代OPC--用户列表
  <div class="pull-right btn-group">
      <a href="{{ url_for('op_bp.add_user') }}" class="btn btn-xs btn-success"
         style="margin-right: 5px;" target="_blank">
          新建用户
      </a>
      <a href="{{ url_for('op_bp.import_pre_users') }}" class="btn btn-xs btn-success"
         style="margin-right: 5px;" target="_blank">
          导入营销用户
      </a>
  </div>
{% endblock %}

{% block panel_body %}
    {{ search_user_form_macro.gen_form(form, tag_form, current_user) }}


    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, 'op_bp.user_list', **url_kwargs) }}
    </div>
    {% endif %}

    {{ user_table_macro.gen_table(users) }}

    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, 'op_bp.user_list', **url_kwargs) }}
    </div>
    {% endif %}

{% endblock %}

{% block scripts %}
{{ super() }}

<script>
    $(document).ready( function () {
        // 省份与城市联动
        function get_city_choices(){
            var prov_name = $("#prov").val();
            if(prov_name != -1){
                $.ajax({
                    url: "{{ url_for('op_bp.ajax_get_cities') }}" + "?prov_name=" + prov_name,
                    cache: true
                }).done(function(data){
                    var city_val = $("#city").val();
                    // console.log(city_val);
                    $("#city").empty();
                    for (var i = 0; i < data["choices"].length; i++) {
                        var id = data["choices"][i]["id"];
                        var name = data["choices"][i]["name"];
                        $("#city").append(
                            "<option value='" + id + "'>" + name + "</option>"
                        );
                    }
                    $("#city").val(city_val);
                }).fail(function(){
                    alert("获取城市列表失败，请联系系统管理员!")
                });

            }
        }
        // 初始化城市选项
        get_city_choices();
        // 绑定省份change事件
        $("#prov").change(function (){
            get_city_choices();
        });

        $('#tag-spread-btn').click(function () {
            var tag_body = $('#tags-wrapper');
            var icon = $('#display-icon');
            if (tag_body.hasClass('hidden')) {
                tag_body.removeClass('hidden');
                icon.removeClass('glyphicon-menu-down');
                icon.addClass('glyphicon-menu-up');
            }
            else {
                tag_body.addClass('hidden');
                icon.removeClass('glyphicon-menu-up');
                icon.addClass('glyphicon-menu-down');
            }
            return false;
        });

        $("#export-users").click(function () {
            var url = '{{ url_for('op_bp.export_user_list') }}';
            url = url + '?' +
                'id=' + $('#id').val() +
                '&type=' + $('#type').val() +
                '&level=' + $('#level').val() +
                '&mobile=' + $('#mobile').val() +
                '&nickname=' + $('#nickname').val() +
                '&prov=' + $('#prov').val() +
                '&city=' + $('#city').val() +
                '&active=' + $('#active').val() +
                '&status=' + $('#status').val() +
                '&follow_state=' + $('#follow_state').val() +
                '&aspiration=' + $('#aspiration').val() +
                '&gold_aspiration=' + $('#gold_aspiration').val() +
                '&supplier_aspiration=' + $('#supplier_aspiration').val() +
                '&pay_aspiration=' + $('#pay_aspiration').val() +
                '&paid_feel=' + $('#paid_feel').val() +
                '&mastery=' + $('#mastery').val() +
                '&scale=' + $('#scale').val() +
                '&contact_frequency=' + $('#contact_frequency').val() +
                '&injured=' + $('#injured').val() +
                '&impression=' + $('#impression').val() +
                '&business=' + $('#business').val();
            if ($('#binded_wx').is(':checked')) {
                url = url + '&binded_wx=1'
            }
            if ($('#black').is(':checked')) {
                url = url + '&black=1'
            }
            window.location.href = url;
        });
    });
</script>
{% endblock %}

